package com.drug.mingkang.controller;

import com.drug.mingkang.model.ImmAppear;
import com.drug.mingkang.model.ImmRepertory;
import com.drug.mingkang.model.vo.ImmPurchaseVo;
import com.drug.mingkang.model.vo.InventoryVo;
import com.drug.mingkang.permission.model.PerUsers;
import com.drug.mingkang.service.ImmRepertoryService;
import com.drug.mingkang.utils.ResponseMessage;
import com.drug.mingkang.utils.Tools;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 分店库存(ImmRepertory)表控制层
 *
 * @author wenchangjian
 * @since 2020-08-11 12:00:14
 */
@RestController
@RequestMapping("immRepertory")
public class ImmRepertoryController {
    /**
     * 服务对象
     */
    @Resource
    private ImmRepertoryService immRepertoryService;

    @Resource
    private Tools tools;


    /**
     * 入库
     * @param remark
     * @return
     */
    @PostMapping("ruku")
    public ResponseMessage ruku(String remark ,String appearTime ,String purchaseDeatis, HttpSession session) throws ParseException {
        return immRepertoryService.updateBePutStorage(remark,appearTime, purchaseDeatis, session);
    }

    /**
     * 查询所有分公司药品库存
     */
    @ApiOperation(value = "查询所有分公司药品库存", notes = "查询所有分公司药品库存", httpMethod = "POST", response = Map.class)
    @PostMapping("/showDrugInventoryAll")
    public Map<String, Object> showDrugInventoryAll(InventoryVo inventoryVo,HttpSession session){
        PerUsers perUsers = (PerUsers) session.getAttribute("perUsers");
        //查询登录用户所在的公司
        inventoryVo.setCompanyId(perUsers.getCompanyId());
        return immRepertoryService.showDrugInventoryAll(inventoryVo);
    }

    /**
     * 根据药品id查看出入库明细
     * @param id 药品id
     * @param session 当前会话
     * @return
     */
    @ApiOperation(value = "根据库存id查看出入库明细", notes = "输入药品id", httpMethod = "POST", response = List.class)
    @PostMapping("/findByRepertoryId")
    public Map<String,Object> findByRepertoryId(String id,int page,int limit,HttpSession session){
        PerUsers perUsers = (PerUsers) session.getAttribute("perUsers");
        return immRepertoryService.findByRepertoryId(id, perUsers.getCompanyId(), page, limit);
    }

}